package com.ermaosk.juc.thread;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadTest {
    static Logger logger = LoggerFactory.getLogger(ThreadTest.class);

    public static void testThread() {

        Thread myThread = new Thread(){
            @Override
            public void run() {
                logger.debug("this is Thread");
            }
        };

        myThread.start();

    }

    public static void testRunnable() {
        new Thread(() -> logger.debug("this is runnable")).start();
    }

    public static void testFutureTask() throws ExecutionException, InterruptedException {
        FutureTask futureTask = new FutureTask<>(() -> {
            logger.debug("this is futureTask");
            Thread.sleep(1000);
            return 100;
        });

        new Thread(futureTask).start();
        logger.info("getResult {}", futureTask.get());
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        testThread();
        testRunnable();
        testFutureTask();
    }
}
